home *** CD-ROM | disk | FTP | other *** search
- unit Cut_sub;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls;
-
- var
- dummy: Integer;
- function cutSub(cutFileName:String; cutBmp: TBitMap): Integer;
- function cutType(Ptr:PChar; cutBmp2:TBitMap): Boolean;
- function expand1(org:PChar; count:Integer; cond:PChar): Integer;
- function expand2(org2:PChar; count2:Integer; cond2, lbuff:PChar): Integer;
- function cutType2(Ptr2:PChar; cutBmp3:TBitMap): Boolean;
- function cutPrint(xbuff: PChar; cutWidth, ofset: Integer; cutBmpExe:TBitMap): Boolean;
-
- implementation
- uses
- Dc_main;
-
- function cutSub(cutFileName:String; cutBmp: TBitMap): Integer;
- type
- bytePtr = ^Char;
- var
- f: file of Byte;
- fileHdl, i, cutOk: Integer;
- cutPt, cutPt2, nstr: PChar;
- buf: Char;
- header, buff, msg: String;
- cutSize: Longint;
- begin
- { File Exists? }
- if FileExists(cutFileName) = False then
- begin
- msg := 'カットファイル"' + cutFileName + '"が見つかりません!';
- MessageDlg(msg, mtError, [mbOK], 0);
- cutSub := 0;
- exit;
- end;
- { CutTypeProcced }
- AssignFile(f, cutFileName);
- Reset(f);
- try
- cutSize := FileSize(f);
- GetMem(cutPt, cutSize);
- try
- BlockRead(f, cutPt^, cutSize);
- finally
- { CutFile? }
- cutPt2 := cutPt;
- GetMem(nstr, 64);
- StrPas(StrMove(nstr, cutPt, 48));
- Inc(cutPt,48);
- cutOk := 0;
- if (compareText('CUT_V', Copy(StrPas(nstr),1,5)) = 0) then
- begin
- cutType(cutPt, cutBmp);
- cutOk := 1;
- end;
- if (nstr[0] = Chr(0)) then
- begin
- cutType2(cutPt, cutBmp);
- cutOk := 1;
- end;
- { Dispose Memory }
- FreeMem(nstr, 64);
- FreeMem(cutPt2, cutSize);
- cutSub := 1;
- end;
- finally;
- CloseFile(f);
- end;
- end;
-
- function cutType(Ptr:PChar; cutBmp2: TBitMap): Boolean;
- var
- xx, yy, xsize, image_y, i: Integer;
- sstr, buffer, bufferPt: PChar;
- head, body: PChar;
- con1, con2, con1buff: PChar;
- dmy, j, y_ofset: integer;
- dmyStr: String;
- dmynull: PChar;
- lineBuf: PChar;
- cutRc: TRect;
- begin
- { CutSize? xx,yy }
- GetMem(sstr, 10);
- xx := Integer(Ptr^) * 256;
- Inc(Ptr, 1);
- xx := xx + Integer(Ptr^);
- Inc(Ptr, 1);
- yy := Integer(Ptr^) * 256;
- Inc(Ptr, 1);
- yy := yy + Integer(Ptr^);
- Inc(Ptr, 1);
- FreeMem(sstr, 10);
- { BitMap }
- cutBmp2.canvas.brush.color := clGreen;
- cutBmp2.canvas.FillRect(cutRc);
- cutBmp2.width := xx;
- cutBmp2.height := yy;
- cutBmp2.Monochrome := False;
- { typeCut }
- GetMem(buffer, 256*16);
- GetMem(con1, 256);
- GetMem(con2, 256);
- GetMem(lineBuf, 256);
- xsize := (xx - 1) div 8 + 1;
- image_y := 0;
- y_ofset := -16;
- bufferPt := buffer;
-
- GetMem(dmyNull, 10);
-
- expand2(buffer, 0, con2, lineBuf);
- for i:=1 to yy do
- begin
- con1buff := con1;
- dmy := Integer(Ptr^);
- for j:=1 to dmy do
- begin
- con1buff^ := Ptr^;
- Inc(Ptr, 1);
- Inc(con1buff, 1);
- end;
- dmy := Integer(con1^);
-
- if (dmy<=0) then break;
- expand1(con2, xsize, con1);
- expand2(buffer, xsize, con2, lineBuf);
- Inc(buffer, xsize);
-
- Inc(image_y, 1);
- Inc(y_ofset, 1);
- if (image_y = 16) then
- begin
- image_y := 0;
- buffer := bufferPt;
- cutPrint(buffer, xx, y_ofset, cutBmp2);
- end;
- Application.ProcessMessages;
- end;
- if (image_y > 0) then
- begin
- buffer := bufferPt;
- cutPrint(buffer, xx, y_ofset, cutBmp2);
- end;
- FreeMem(lineBuf, 256);
- FreeMem(con2, 256);
- FreeMem(con1, 256);
- FreeMem(bufferPt, 256*16);
- { Reset FormSize }
- cutRc := Rect(0,0,xx,yy);
- end;
-
- function expand1(org:PChar; count:Integer; cond:PChar): Integer;
- var
- pt, bt, flag, i: Integer;
- head, body: PChar;
- begin
- if (cond^ = Chr(1))then
- begin
- for pt:=1 to count do
- begin
- org^ := Chr(0);
- Inc(org, 1);
- end;
- expand1 := count;
- exit;
- end;
- pt := (count - 1) div 8 + 1;
- head := cond + 1;
- body := head + pt;
- for i:= 1 to Pt do
- begin
- flag := Integer(head^);
- Inc(head, 1);
- for bt:=0 to 7 do
- begin
- if ((flag And 128) = 0) then
- org^ := Chr(0)
- else
- begin
- org^ := body^;
- Inc(body, 1);
- end;
- Inc(org, 1);
- flag := flag shl 1;
- end;
- end;
- expand1 := count;
- end;
-
- function expand2(org2:PChar; count2:Integer; cond2, lbuff:PChar): Integer;
- var
- c: Integer;
- begin
- if (count2 = 0) then
- begin
- for c := 1 to 128 do
- begin
- lbuff^ := Char(0);
- Inc(lbuff, 1);
- end;
- expand2 := count2;
- exit;
- end;
- for c:=1 to count2 do
- begin
- org2^ := Chr(Integer(cond2^) Xor Integer(lbuff^));
- lbuff^ := org2^;
- Inc(org2, 1);
- Inc(cond2, 1);
- Inc(lbuff, 1);
- end;
- expand2 := count2;
- end;
-
- function cutType2(Ptr2:PChar; cutBmp3: TBitMap): Boolean;
- var
- xx, yy, xsize, image_y, i: Integer;
- sstr, buffer, bufferPt: PChar;
- head, body: PChar;
- dmy, j, y_ofset: integer;
- dmyStr: String;
- dmynull: PChar;
- lineBuf: PChar;
- cutRc: TRect;
- begin
- { CutSize? xx,yy }
- GetMem(sstr, 10);
- xx := Integer((Ptr2+16)^) * 256;
- xx := xx + Integer((Ptr2+17)^);
- yy := Integer((Ptr2+18)^) * 256;
- yy := yy + Integer((Ptr2+19)^);
- FreeMem(sstr, 10);
- if (xx<=0) Or (yy<=0) Or (xx>1024) Or (yy>1024) then exit;
- Inc(Ptr2, 20);
- { BitMap }
- cutBmp3.canvas.brush.color := clGreen;
- cutBmp3.canvas.FillRect(cutRc);
- cutBmp3.width := xx;
- cutBmp3.height := yy;
- cutBmp3.Monochrome := False;
- { typeCut }
- if ((xx mod 8) = 0) then
- xsize := (xx div 8) * 16
- else
- xsize := ((xx div 8) + 1) * 16;
- y_ofset := 0;
- for i:=1 to (yy div 16) do
- begin
- cutPrint(Ptr2, xx, y_ofset, cutBmp3);
- Inc(Ptr2, xsize);
- Inc(y_ofset, 16);
- {Application.ProcessMessages;}
- end;
- if ((yy Mod 16) > 0) then
- begin
- cutPrint(Ptr2, xx, y_ofset-16+(yy Mod 16), cutBmp3);
- end;
- { Reset FormSize }
- cutRc := Rect(0,0,xx,yy);
- end;
-
- function cutPrint(xbuff: PChar; cutWidth, ofset: Integer; cutBmpExe: TBitMap): Boolean;
- var
- cr: PChar;
- flg2: Integer;
- i,j,k,ke:Integer;
- x_offset, cll, cll2: Integer;
- begin
- if ((ofset mod 16) = 0) then
- ke := 15
- else
- begin
- ke := ofset Mod 16 - 1;
- ofset := ofset + 16 - ke - 1;
- end;
- for k:= 0 to ke do
- begin
- cutBmpExe.canvas.pen.color := clGreen;
- cutBmpExe.canvas.MoveTo(-1,ofset + k);
- for i:=0 to (cutWidth div 8)-1 do
- begin
- flg2 := 128;
- x_offset := i*8;
- for j:=0 to 7 do
- begin
- if ( Integer(xbuff^) And flg2 <> 0) then
- cll := 1
- else
- cll := 0;
- if (cll <> cll2) then
- begin
- if (cll = 1) then
- begin
- cutBmpExe.canvas.pen.color := clGreen;
- cutBmpExe.canvas.moveTo(x_offset+j,ofset + k);
- end;
- if (cll = 0) then
- begin
- cutBmpExe.canvas.pen.color := clWhite;
- cutBmpExe.canvas.LineTo(x_offset+j,ofset + k);
- end;
- cll2 := cll;
- end;
- flg2 := flg2 shr 1;
- end;
- Inc(xbuff, 1);
- end;
- if ((cutWidth mod 8) > 0) then
- begin
- flg2 := 128;
- x_offset := (i+1)*8;
- for j:=0 to (cutWidth mod 8) do
- begin
- if ( Integer(xbuff^) And flg2 <> 0) then
- cll := 1
- else
- cll := 0;
- if (cll <> cll2) then
- begin
- if (cll = 1) then
- begin
- cutBmpExe.canvas.pen.color := clGreen;
- cutBmpExe.canvas.moveTo(x_offset+j,ofset + k);
- end;
- if (cll = 0) then
- begin
- cutBmpExe.canvas.pen.color := clWhite;
- cutBmpExe.canvas.LineTo(x_offset+j,ofset + k);
- end;
- cll2 := cll;
- end;
- flg2 := flg2 shr 1;
- end;
- Inc(xbuff, 1);
- end;
- if (cll = 0) then
- begin
- cutBmpExe.canvas.pen.color := clGreen;
- cutBmpExe.canvas.lineTo(cutWidth,ofset + k);
- end;
- if (cll = 1) then
- begin
- cutBmpExe.canvas.pen.color := clWhite;
- cutBmpExe.canvas.LineTo(cutWidth,ofset + k);
- end;
- end;
- end;
-
-
-
-
- end.
-